import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import org.ukui.quick.widgets 1.0 // 导入ukui-quick插件框架模块
import QtQuick.Controls 2.15 as Controls

import QtQuick.Window 2.15

WidgetItem {
    id: rootWidget
    Layout.fillHeight: true
    Layout.preferredWidth: 60
    clip: false

    // 节气名称和日期
    property var solarTerms: [
        {name: "立春", date: "02-04"},
        {name: "雨水", date: "02-19"},
        {name: "惊蛰", date: "03-06"},
        {name: "春分", date: "03-21"},
        {name: "清明", date: "04-05"},
        {name: "谷雨", date: "04-20"},
        {name: "立夏", date: "05-06"},
        {name: "小满", date: "05-21"},
        {name: "芒种", date: "06-06"},
        {name: "夏至", date: "06-21"},
        {name: "小暑", date: "07-07"},
        {name: "大暑", date: "07-23"},
        {name: "立秋", date: "08-07"},
        {name: "处暑", date: "08-23"},
        {name: "白露", date: "09-08"},
        {name: "秋分", date: "09-23"},
        {name: "寒露", date: "10-08"},
        {name: "霜降", date: "10-23"},
        {name: "立冬", date: "11-07"},
        {name: "小雪", date: "11-22"},
        {name: "大雪", date: "12-07"},
        {name: "冬至", date: "12-22"},
        {name: "小寒", date: "01-05"},
        {name: "大寒", date: "01-20"}
    ]

    // 获取当前日期
    function getCurrentDate() {
        var date = new Date();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        return month.toString().padStart(2, '0') + '-' + day.toString().padStart(2, '0');
    }

    // 获取当前节气
    function getCurrentSolarTerm() {
        var currentDate = getCurrentDate();
        var currentYear = new Date().getFullYear();
        for (var i = 0; i < solarTerms.length; i++) {
            var termDate = currentYear + '-' + solarTerms[i].date;
            if (currentDate <= termDate) {
                return solarTerms[i].name;
            }
        }
        return solarTerms[0].name; // 默认返回第一个节气
    }

    // 显示当前节气
    Text {
        id: solarTermText
        text: getCurrentSolarTerm()
        font.pixelSize: 16
        anchors.centerIn: parent
    }

    Component.onCompleted: {
        solarTermText.text = getCurrentSolarTerm();
    }
}
